Skip to content

feat(carve): carve bridge — patch the surviving Terraform (#197) - #996

Merged
lex00 merged 1 commit into
mainfrom
feat/terraform-carve-bridge
Jul 22, 2026
Merged

lex00 merged 1 commit into
mainfrom
feat/terraform-carve-bridge

Conversation

@lex00

@lex00 lex00 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

The boundary-bridging centerpiece of the strangler-fig carve (#197), on top of carve emit (#995). chant carve bridge --from <tf-dir> --select <address> generates the edits to the Terraform you leave behind so its plan stays valid once the resource is chant-owned.

What it generates

  • Inbound edges → a data source for the (now chant-managed) carved resource, plus rewired type.name.attr → data.type.name.attr references in the survivors. The survivor keeps reading the resource, via a data source instead of a managed one.
  • Outbound edges → recorded as deferred deploy-time inputs, wired when you turn the dial to apply.
  • A reversible, observe-first runbook: terraform state rm (does not destroy), patch survivors, adopt into chant, with a terraform import rollback at every step before graduation.

Safety

  • Read-only by default: proposals (data sources, rewritten survivors, runbook) are written to an output dir. Your Terraform is untouched.
  • --apply-rewrites edits the survivor .tf in place — opt-in mutation only.
  • The rewrite is idempotent (never double-prefixes data.), and leaves the carved resource's own resource "type" "name" declaration (quoted labels) alone.

Notes

  • Removing the carved resource's own block from the .tf is left as a runbook step, not auto-edited: hcl2json gives a JSON tree without source spans, so precise block excision from HCL text isn't reliable. The data-source insertion + reference rewiring — the part that breaks plan if missed — is generated.

Verification

  • 12 new tests (pure bridge transform + command dry-run / in-place); full terraform + carve suites green.
  • Core tsc + eslint clean. Verified end-to-end via the real CLI.

Part of #197.

The boundary-bridging centerpiece. `chant carve bridge --from <tf-dir>
--select <address>` generates the edits to the Terraform you leave behind so
its plan stays valid once the resource is chant-owned:

- inbound edges → a `data` source for the carved resource + rewired
  `type.name.attr` references (survivor keeps reading it, now via data).
- outbound edges → recorded as deferred deploy-time inputs (wired at apply).
- a reversible, observe-first handoff runbook (state rm, patch, import-back).

Safe by default: writes proposals to an output dir for review. --apply-rewrites
edits the survivor .tf in place (opt-in). The rewrite is idempotent, never
double-prefixes a data ref, and leaves the carved resource's own declaration
(quoted labels) untouched. Pure text transform, fully unit-tested.

PR B of 3 (#197). Next: apply graduation (ownership marker + opt-in apply).
@lex00
lex00 merged commit 80d11e6 into main Jul 22, 2026
5 checks passed
@lex00
lex00 deleted the feat/terraform-carve-bridge branch July 22, 2026 04:48
lex00 added a commit that referenced this pull request Jul 22, 2026
)

Apply graduation, the dial-turn from observe to apply. `chant carve apply
--from <tf-dir> --select <address> --env <env>` resolves the ownership marker
that makes the carved resource chant-owned (reusing core ownershipEntries) and
finalizes the ordered apply runbook.

BYOL-honest: no cloud call. It computes the marker + plan; the apply is your
lifecycle (native CLI / CI / ApplyOp), which stamps the marker the emitted
source carries. --write saves the graduation doc.

- terraform/graduate.ts: ownership marker + tags (chant:managed-by/stack/env,
  mirroring the AWS lexicon's tag channel) + reversible runbook.
- carve apply command: dry-run plan by default; --write emits the doc.
- docs: cli/carve-out.mdx documents the full emit → bridge → apply arc.
- carve-arc.test.ts: end-to-end, one resource through all three steps.

PR C of 3 — completes the boundary-bridging carve (#197). emit + bridge +
apply now compose end to end (advisor #214 → emit #995 → bridge #996 → apply).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant